package com.tianzeculture.stagebao.activity.artist.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.ArtistEditVideoActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.ArtistsBean;

import java.util.List;

/**
 * Created by Administrator on 2018/8/15.
 */

public class PushWorksAdapter extends RecyclerView.Adapter<PushWorksAdapter.RecyclerViewHolder> {
    Context context;
    List<String> uriList;
    boolean isVideo;

    public PushWorksAdapter(Context context, List<String> uriList, boolean isVideo) {
        this.context = context;
        this.uriList = uriList;
        this.isVideo = isVideo;
    }

    public PushWorksAdapter(Context context) {
        this.context = context;
    }

    @Override
    public PushWorksAdapter.RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_push_works, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }

    public void setUriList(List<String> uriList) {
        this.uriList = uriList;
    }


    @Override
    public int getItemCount() {
        if (isVideo) {
            return 1;
        }
        return uriList == null ? 1 : uriList.size() + 1;
    }

    WorksListener listener;

    public interface WorksListener {
        void workClick(int position, boolean isVideo);
    }

    public void setWorkListener(WorksListener listener) {
        this.listener = listener;
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder {

        ImageView ivWorks;
        ImageView ivClose;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            ivWorks = itemView.findViewById(R.id.iv_works);
            ivClose = itemView.findViewById(R.id.ivClose);
        }

        public void setData(final int position) {
            ivClose.setVisibility(View.GONE);
            ivWorks.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null) {
                        listener.workClick(position, isVideo);
                    }
                }
            });
            if (uriList == null) {
                Glide.with(context).load(R.mipmap.icon_shangchuan).skipMemoryCache(true).into(ivWorks);
                return;
            }
            if (position == uriList.size() && !isVideo) {
                Glide.with(context).load(R.mipmap.icon_shangchuan).skipMemoryCache(true).into(ivWorks);
                return;
            }
            Glide.with(context).load(uriList.get(position)).skipMemoryCache(true).into(ivWorks);

        }
    }
}
